<%@ page import="controllers.UploadConnect"%>
<%@ page import="java.util.List,java.text.*"%>
<%@ page import="java.util.List,java.util.HashMap"%>
<%@ page import="models.COPSTemp"%>
<%@ page import="controllers.AppServletContextListener"%>
<%@ page import="com.googlecode.objectify.Objectify"%>
<%@ page import="com.googlecode.objectify.ObjectifyService"%>
<%@ page import="com.googlecode.objectify.Query"%>
<%@ page import="com.google.appengine.api.blobstore.BlobKey"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%

UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String user_email = user.getEmail().toLowerCase();



	String awd_file = "";
	BlobKey blob_key;
	String _key = (String) request.getParameter("tempPicKey");
	boolean ifound = false;
	Objectify ofy = ObjectifyService.begin();
	Query<COPSTemp> q = ofy.query(COPSTemp.class).filter("CreateBy", user_email).order("CreateDate");
	for (COPSTemp f : q.fetch()) {
		blob_key = f.getTempPicKey();
		if (blob_key != null) {
			awd_file = blob_key.getKeyString();
		}
		break;
	}
%>


<link rel="stylesheet" type="text/css" href="/css/iehacks1.css">
<link rel="stylesheet" type="text/css" href="/css/blog.css">
<link rel="stylesheet" type="text/css" href="/css/coreBlue.css">
<script src="/Jcrop/js/jquery.min.js"></script>
<script src="/Jcrop/js/jquery.Jcrop.min.js"></script>
<script src="/Jcrop/js/jquery.FieldsetToggle.js"></script>
<script src="/Jcrop/js/jcrop_demos.js"></script>









<script language="Javascript">
	function checkCoords()
	{
	    if (parseInt(jQuery('#w').val())>0) return true;
	    alert('Please select a crop region then press submit.');
	    return false;
	};
</script>

<body>

	<script language="Javascript">
					// Remember to invoke within jQuery(window).load(...)
					// If you don't, Jcrop may not initialize properly
					$(function() {

						$('#jcrop_target').Jcrop({
							onChange : showPreview,
							onSelect : showPreview,
							onRelease : hidePreview,
							aspectRatio : 1
						});

						var $preview = $('#preview');
						// Our simple event handler, called from onChange and onSelect
						// event handlers, as per the Jcrop invocation above
						function showPreview(coords) {
							if (parseInt(coords.w) > 0) {
								var rx = 100 / coords.w;
								var ry = 100 / coords.h;

								$preview
										.css(
												{
													width : Math
															.round(rx * 500)
															+ 'px',
													height : Math
															.round(ry * 370)
															+ 'px',
													marginLeft : '-'
															+ Math.round(rx
																	* coords.x)
															+ 'px',
													marginTop : '-'
															+ Math.round(ry
																	* coords.y)
															+ 'px'
												}).show();
							}
						}

						function hidePreview() {
							$preview.stop().fadeOut('fast');
						}

					});
				</script>

	<table>
		<tbody>
			<tr>
				<td style="padding: 5px;"><img
					src="/blobserve?blob-key=<%=awd_file%>" id="jcrop_target"
					style="display: none; visibility: hidden; width: 500px; height: 370px;">
				</td>
				<td valign="top">

	
							<td>Image Preview:

								<div  style="width: 100px; height: 100px; overflow: hidden; margin-left: 5px;">
									<img src="/blobserve?blob-key=<%=awd_file%>" id="preview" style="width: 238px; height: 176px; display: none;">
								</div>
				</td>
			</tr>
			<tr>
			   <td colspan="1" align="left" >
			        <input type="button" value="UploadFile" onclick="UploadImage()"  id="btnSubmitPhoto">
			         <input type="button" value="upload" onclick="UploadImage()"  id="btnUpload" >
			   </td>
			</tr>
		</tbody>
	</table>
	<script type="text/javascript">
		var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl."
				: "http://www.");
		document
				.write(unescape("%3Cscript src='"
						+ gaJsHost
						+ "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
	</script>
	<script src="http://www.google-analytics.com/ga.js"
		type="text/javascript"></script>
	<script type="text/javascript">
		var pageTracker = _gat._getTracker("UA-5176876-1");
		pageTracker._trackPageview();
	</script>
</body>


















